/*
* OctLabel.cpp
*
* Copyright(C) 2009, Лущик Павел aka nanoo
*
* This code is lisenced under the GPL version 2. For details see 
* LISENCE.txt
*/

#include"OctLabel.h"
void define_and_set_state(OctLabel*,int);

OctLabel::OctLabel(QWidget *parent): QLabel(parent)
{
	state=00;
	setFrameStyle(QFrame::Panel| QFrame::Sunken);
	go_up();
	setToolTip(tr("Use mouse wheel to change the value"));
}

void OctLabel::wheelEvent(QWheelEvent *ev)
{
	ev->accept();
	if(ev->delta()>0){
		go_up();
	} else {
		go_down();
	}
	emit wheel_is_running();
}

void OctLabel::go_up()
{
	state++;
	if(state>07){
		state=00;
		emit up();
	}
	define_and_set_state(this,state);
}

void OctLabel::go_down()
{
	state--;
	if(state<00){
		state=07;
		emit down();
	}
	define_and_set_state(this,state);
}

int OctLabel::value()
{
	return state;
}

void OctLabel::setValue(int a){
	if(a>=00||a<=07){
		state=a;
	}
	define_and_set_state(this,state);
}

void define_and_set_state(OctLabel* a, int state){
	switch(state){
		case 00: a->setText("<b>0</b>"); break;
		case 01: a->setText("<b>1</b>"); break;
		case 02: a->setText("<b>2</b>"); break;
		case 03: a->setText("<b>3</b>"); break;
		case 04: a->setText("<b>4</b>"); break;
		case 05: a->setText("<b>5</b>"); break;
		case 06: a->setText("<b>6</b>"); break;
		case 07: a->setText("<b>7</b>"); break;
	}
}
